Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

All: Conflict notes will now populate a new field conflict_parent with the id of the conflict note. #5049

Merged
merged 17 commits into from
Jun 12, 2021

Conversation

Ahmad45123
Copy link
Contributor

As the title says. Pretty simple change to be used with https://github.com/joplin/plugin-conflict-resolution

@laurent22
Copy link
Owner

Should be "conflict_parent_id" for consistency with the rest of the code base.

Also please make sure that the is_conflict and your new field are in sync. If it's "1", your field should be set. If it's "0" it should be unset. I think there are some cases where it's not true.

@roman-r-m
Copy link
Collaborator

roman-r-m commented Jun 5, 2021

I think there are some cases where it's not true.

For instance when there's an unresolved conflict and you update Joplin to a version that includes this change.

@Ahmad45123
Copy link
Contributor Author

Ahmad45123 commented Jun 5, 2021

I think there are some cases where it's not true.

For instance when there's an unresolved conflict and you update Joplin to a version that includes this change.

Hmm how do I recover the original note ID though ? Unless I set it when a conflict occurs, I believe there's no way to know.

@laurent22
Copy link
Owner

For instance when there's an unresolved conflict and you update Joplin to a version that includes this change.

Normally the is_conflict field is set to 1 only during sync so I'm not sure how updating Joplin would cause an issue?

@roman-r-m
Copy link
Collaborator

roman-r-m commented Jun 6, 2021

Normally the is_conflict field is set to 1 only during sync so I'm not sure how updating Joplin would cause an issue?

I was trying to say that when @Ahmad45123 is going to add logic that relies on this field he can't assume that each conflicted note will have it set.

Maybe there should be an option to set it manually?

@laurent22
Copy link
Owner

I was trying to say that when @Ahmad45123 is going to add logic that relies on this field he can't assume that each conflicted note will have it set.

This field being set is what defines a conflicted note, so it would definitely be set. When a conflict is detected a new note is created with "is_conflict" set to 1. So it's not possible to create such note without the field being set.

@roman-r-m
Copy link
Collaborator

This field being set is what defines a conflicted note, so it would definitely be set. When a conflict is detected a new note is created with "is_conflict" set to 1. So it's not possible to create such note without the field being set.

I meant the new field that this PR introduces -- conflict_parent_id

@Ahmad45123
Copy link
Contributor Author

Ahmad45123 commented Jun 6, 2021

I was trying to say that when @Ahmad45123 is going to add logic that relies on this field he can't assume that each conflicted note will have it set.

Oh right! Ty for the note. Though, I think that will be handled in the plugins side? Maybe I'll use it if exists and otherwise ask the user to select the other note as some sort of backwards compatibly.

I've also made it to reset conflict_parent_id when copying or moving notes. I think that's the only case where is_conflict is modified to zero from one.

packages/lib/models/Note.ts Outdated Show resolved Hide resolved
packages/lib/models/Note.ts Outdated Show resolved Hide resolved
@Ahmad45123
Copy link
Contributor Author

Ok so I've done:

  • Added tests for copyToFolder and moveToFolder. This is like my first ever unit test so please excuse me if there's any issues.
  • I also did what you suggested in Synchronizer.conflicts.test.ts

packages/lib/models/Note.test.ts Outdated Show resolved Hide resolved
packages/lib/models/Note.test.ts Outdated Show resolved Hide resolved
packages/lib/models/Note.test.ts Outdated Show resolved Hide resolved
packages/lib/models/Note.test.ts Outdated Show resolved Hide resolved
@Ahmad45123
Copy link
Contributor Author

I've fixed the issues. I hope it's okay now :)

@Ahmad45123 Ahmad45123 changed the title All: Conflict notes will now populate a new field conflict_parent with the id of the conflict note,. All: Conflict notes will now populate a new field conflict_parent with the id of the conflict note. Jun 9, 2021
Comment on lines 342 to 346
const tmpConflictedNote = Object.assign({}, note1);
delete tmpConflictedNote.id;
tmpConflictedNote.is_conflict = 1;
tmpConflictedNote.conflict_original_id = note1.id;
const conflictedNote = await Note.save(tmpConflictedNote, { autoTimestamp: false });
Copy link
Owner

@laurent22 laurent22 Jun 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't copy and paste large blocks of code in this codebase, it's just a mess to maintain otherwise. So please do this:

  • Create a function in models/Note called public async createConflictNote(sourceNote:NoteEntity, changeSource:number):Promise<NoteEntity>
  • Make it create the conflict note and save it as in the code above.
  • Then use that function in:
    • Your two test units
    • In lib/Synchronizer.ts

As a general rule if you see you are copying more than two or three lines of code, you should stop and think if the code can be refactored. Such refactoring improves the code quality because it wraps and names (using the function name) business logic and makes it re-usable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be good now.

@Ahmad45123
Copy link
Contributor Author

This is ready for another review.

Comment on lines 355 to 358
// Source conflict should stay as is
expect(conflictedNote.is_conflict).toBe(1);
expect(conflictedNote.conflict_original_id).toBe(note1.id);
expect(conflictedNote.parent_id).toBe(srcfolder.id);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to test the output of createConflictNote, it should be in a separate test, so please remove this part.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll move it to a separate test.


const conflictedNote = await Note.createConflictNote(note1, ItemChange.SOURCE_SYNC);

// Move
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In your comments you should explain why, not what. We know that a function called "Note.moveToFolder" is going to move the note to a folder, and a comment for this is just noise. I don't think you need to explain anything here, so please remove the comment.


const conflictedNote = await Note.createConflictNote(note1, ItemChange.SOURCE_SYNC);

// COPY File
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your comment explains nothing and is even confusing since we aren't moving files but notes, so please remove it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted. Also no idea myself where did "File" come from 😂 sorry about that

@@ -332,4 +333,49 @@ describe('models_Note', function() {
expect(sortedNotes3[4].id).toBe(note2.id);
}));

it('should copy conflicted note to target folder and cancel conflict', (async () => {
// Prepare
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove

}));

it('should move conflicted note to target folder and cancel conflict', (async () => {
// Prepare
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove

@Ahmad45123
Copy link
Contributor Author

Should be good for another review. :)

@laurent22
Copy link
Owner

Ok, you're the first pull request that uses the new GitHub Actions CI, so let's see if all the tests pass.

@Ahmad45123
Copy link
Contributor Author

Hmm I'll check the failed tests in a few minutes.

@laurent22
Copy link
Owner

laurent22 commented Jun 11, 2021

If you are going to fix the test by committing and waiting for the full CI to run it might take a while. Instead you should look where the failure happens and run the tests locally inside the right package only.

In that particular case, you can run npm test from within packages/server.

@Ahmad45123
Copy link
Contributor Author

Ahmad45123 commented Jun 11, 2021

If you are going to fix the test by committing and wait for the full CI to run it might take a while. Instead you should look where the failure happen and run the tests locally inside the right package only.

In that particular case, you can run npm test from within packages/server.

I tried but I'm having trouble getting the server tests running locally. In fact, thats exactly why I missed this failing test. They all fail so I just ignored them.

This is a portion of logs: https://pastebin.com/YXpyKNwx

I think it has to do with Sqlite somehow.

@laurent22
Copy link
Owner

Could you use WSL instead? Otherwise you'll keep getting issues like this.

@Ahmad45123
Copy link
Contributor Author

Ahmad45123 commented Jun 11, 2021

Spent most of the day to get WSL working haha.. And now all tests pass locally though I've got no idea why did CI fail again :/
Seems you made changes to it though ? Doesn't even reach the actual tests stage if I make sense.

E: Please review my fix to that server test btw, I don't know how that all works yet and I've got no idea if my fix is correct haha

@laurent22
Copy link
Owner

There was a problem with the CI config but it works now, so let's merge.

@laurent22 laurent22 merged commit 2af3bf6 into laurent22:dev Jun 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants